<script setup lang="ts">
import { GetUserSettingAPI, UpdateUserSettingAPI } from '@/services/detail'
import { DaKaNoteIndex, GetAllNotice, GetAllTask, NoteIndex } from '@/services/notelog'
import { ZiChanIndexAPI } from '@/services/zichan'
import { useMemberStore } from '@/stores'
import type { UserSetting } from '@/types/detail'
import type { DaKa, Note, Notice, TaskInfo } from '@/types/notelog'
import type { ZiChanIndexData } from '@/types/zichan'
import { onLoad, onShow } from '@dcloudio/uni-app'
import { computed, ref } from 'vue'

// 获取屏幕边界到安全区域距离
const { safeAreaInsets } = uni.getSystemInfoSync()
// 获取会员信息
const memberStore = useMemberStore()
const data = ref<TaskInfo[]>()
onShow(async () => {
  onRefresherrefresh()
})
//加载初始化
onLoad(async () => {
  onRefresherrefresh()
})
// 是否触发下拉刷新
const isTriggered = ref(false)
// 自定义下拉刷新被触发
const onRefresherrefresh = async () => {
  // 开始动画
  isTriggered.value = true
  // 加载数据
  if (memberStore.profile) {
    const res = await GetAllTask({
      Auth: memberStore.profile.Token,
      UserGroup: memberStore.profile.UserGroup,
    })
    data.value = res.result
    uni.showToast({ icon: 'success', title: '刷新成功' })
  }
  // 关闭动画
  isTriggered.value = false
}

//返回
const Onleft = () => {
  uni.switchTab({ url: '/pages/my/my' })
}
const Add = () => {
  uni.navigateTo({ url: '/pages/NoteAcount/MyTaskAdd' })
}
</script>
<template>
  <scroll-view
    enable-back-to-top
    scroll-y
    refresher-enabled
    :refresher-triggered="isTriggered"
    @refresherrefresh="onRefresherrefresh"
  >
    <view class="viewport">
      <view class="header" :style="{ paddingTop: safeAreaInsets!.top + 'px' }">
        <view class="left icon-left" @tap="Onleft()"></view>
        <uni-title type="h1" align="center" title="我们的任务" class="text"></uni-title>
        <view class="btn right" @tap="Add">新增</view>
      </view>
      <scroll-view enable-back-to-top scroll-y class="scroll">
        <view class="detail" v-for="(item, index) in data" :key="index">
          <uni-list>
            <uni-list-item
              :class="{
                warn: item.Status == '超时',
                ing: item.Status == '进行中',
                end: item.Status == '完成',
              }"
              link
              :show-badge="true"
              :title="item.TaskTitle"
              :note="item.UserName || '所有人'"
              :to="`./MyTaskAdd?ID=` + item.ID"
              thumb-size="sm"
              clickable
            >
            </uni-list-item>
          </uni-list>
        </view>
      </scroll-view>
    </view>
  </scroll-view>
</template>

<style lang="scss">
@import './styles/NoteLogMain.scss';
</style>
